﻿Imports Negocio
Public Class frmListadoArticulos

    Dim CIA As String = "01"
    Dim dataArticulo As New DataView

    Dim servicio As New KardexNegocio

    Sub listarStocks(empresa As String)
        Dim ds As DataSet = servicio.listadoStockArticulos(empresa, "")
        dataArticulo = ds.Tables(0).DefaultView

        dgvListado.DataSource = dataArticulo
        If dataArticulo.Count > 0 Then
            dgvListado.Rows(0).Selected = False
        End If

        lblConteo.Text = "Nro. Artículos : " & dataArticulo.Count
    End Sub

    Sub letra(texto As String, tipo As String)
        If tipo = "C" Then
            dataArticulo.RowFilter = "ART_Codigo LIKE '%" & texto & "%'"
        ElseIf tipo = "D" Then
            dataArticulo.RowFilter = "Articulo LIKE '%" & texto & "%'"
        End If
    End Sub

    Private Sub ListadoArticulos_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        listarStocks(CIA)
    End Sub

    Private Sub dgvListado_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvListado.CellClick
        Dim f As Integer = e.RowIndex
        Dim c As Integer = e.ColumnIndex

        If f > -1 Then
            If c = 0 Then
                Dim frmKardexDetalle As New frmKardexArticulo(dgvListado.Item("Column1", f).Value, dgvListado.Item("Column2", f).Value,
                                                              dgvListado.Item("Column4", f).Value, dgvListado.Item("Column5", f).Value,
                                                              dgvListado.Item("Column3", f).Value, dgvListado.Item("Column6", f).Value,
                                                              dgvListado.Item("Column7", f).Value)
                If frmKardexDetalle.ShowDialog = Windows.Forms.DialogResult.OK Then

                End If
            End If
        End If
    End Sub

    Private Sub txtArticulo_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtArticulo.TextChanged
        letra(txtArticulo.Text.Trim, "C")
        lblConteo.Text = "Nro. Artículos : " & dataArticulo.Count
    End Sub

    Private Sub txtNomArticulo_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtNomArticulo.TextChanged
        letra(txtNomArticulo.Text.Trim, "D")
        lblConteo.Text = "Nro. Artículos : " & dataArticulo.Count
    End Sub

End Class